package com.eleadmin;

import com.eleadmin.common.core.config.ConfigProperties;
import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * 启动类
 * Created by EleAdmin on 2018-02-22 11:29:03
 */

@EnableAsync
@EnableScheduling
@EnableTransactionManagement
@MapperScan("com.eleadmin.**.mapper")
@EnableConfigurationProperties(ConfigProperties.class)
@SpringBootApplication
public class EleAdminApplication {

    public static void main(String[] args) {
        SpringApplication.run(EleAdminApplication.class, args);
    }
    @Value("${runwithmodel}")
    private String runwithmodel;

    //tenant_id = 2
    //http://127.0.0.1:8081/swagger-ui/index.html


// jar导出到maven
//    https://blog.csdn.net/grq15203514615/article/details/126966572
//    mvn install:install-file -Dfile=openapi-sdk-6.0.jar -DgroupId=com.damon.openapi -DartifactId=mysdk-sdk -Dversion=6.0 -Dpackaging=jar

//<dependency>
//            <groupId>com.damon.openapi</groupId>
//            <artifactId>mysdk-sdk</artifactId>
//            <version>6.0</version>
//        </dependency>





    /**
     * http重定向到https
     * @return
     */
//    @Bean
//    public TomcatServletWebServerFactory servletContainer() {
//        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
//            @Override
//            protected void postProcessContext(Context context) {
//                SecurityConstraint constraint = new SecurityConstraint();
//                constraint.setUserConstraint("CONFIDENTIAL");
//                SecurityCollection collection = new SecurityCollection();
//                collection.addPattern("/*");
//                constraint.addCollection(collection);
//                context.addConstraint(constraint);
//            }
//        };
//        tomcat.addAdditionalTomcatConnectors(httpConnector());
//        return tomcat;
//    }
//
//    @Bean
//    public Connector httpConnector() {
//        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
//        connector.setScheme("http");
//        connector.setSecure(false);
//        //Connector监听的http的端口号
//        //监听到http的端口号后转向到的https的端口号
//
//        if (runwithmodel.equals("dev")) {
//        } else if (runwithmodel.equals("test")) {
//            connector.setPort(9637);
//            connector.setRedirectPort(9337);//--端口号
//        } else if (runwithmodel.equals("prod")) {
//            connector.setPort(4637);
//            connector.setRedirectPort(4337);//--端口号
//        }
//        return connector;
//    }


}
